using System.BusinessObjects.Transactions;
using Blazing.BusinessObjects.Cms;
using NHibernate;
using NHibernate.Criterion;

namespace Blazing.BusinessObjects.Queries
{
    public class QrySearchSites
    {
        public static ICriteria Query()
        {
            ICriteria qry = UnitOfWork.CurrentSession.CreateCriteria(typeof(Site));

            qry.AddOrder(Order.Asc("Name"));

            return qry;
        }

        /// <summary>
        /// Search for a site using Sites and SiteAliases
        /// </summary>
        /// <param name="host"></param>
        /// <returns></returns>
        public static IQuery Query(string host)
        {
            string nql = "select s from Site s where s.Url = :siteHost or s in (select s2 from Site s2 join s2.Aliases sa where sa.Url=:siteHost)";
            IQuery qry = UnitOfWork.CurrentSession.CreateQuery(nql);
            qry.SetString("siteHost", host);
            return qry;
        }

        public static IQuery QuerySitesOnly(string host)
        {
            string nql = "select s from Site s where s.Url = :siteHost";
            IQuery qry = UnitOfWork.CurrentSession.CreateQuery(nql);
            qry.SetString("siteHost", host);
            return qry;
        }
    }
}
